package cn.bbs.ba.util;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import org.apache.commons.lang.StringUtils;
import org.apache.struts.action.ActionForm;

import cn.bbs.ba.base.BaseDto;

public class DtoUtil {

	public static void formToDto(ActionForm form, BaseDto dto) {
		Method[] methArr = form.getClass().getMethods();
		for(int i = 0; i < methArr.length; i++) {
			String strName = methArr[i].getName();
			if (strName.indexOf("get") != -1) {
				try {
					dto.setValue(StringUtils.substring(strName, 3), methArr[i].invoke(form, null));
				} catch (IllegalArgumentException e) {
					e.printStackTrace();
				} catch (IllegalAccessException e) {
					e.printStackTrace();
				} catch (InvocationTargetException e) {
					e.printStackTrace();
				}
			}

		}
	}
}
